package middlewares

import (
	"github.com/gin-gonic/gin"
	"net/http"
	"ruoyi/models"
	"ruoyi/utils/jwtutil"
)

func JwtCheck(c *gin.Context) {
	fullPath := c.FullPath()
	if fullPath == "/api/auth/login" {
		return
	}
	token := c.Request.Header.Get("Authorization")
	if token == "" {
		c.JSON(http.StatusOK, models.Error("未传递token"))
		c.Abort()
		return
	}
	claims, err := jwtutil.ParseToken(token)
	if err != nil {
		c.JSON(http.StatusOK, models.Error("token验证异常"))
		c.Abort()
		return
	}
	c.Set("claims", claims)
}
